package org.jypj.dev.controller;

import org.jypj.dev.dao.ShoesDao;
import org.jypj.dev.model.Shoes;
import org.jypj.dev.util.ShoesUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by ChenYu on 2017-05-17.
 */
@Controller
public class IndexController extends BaseController {
    @Resource
    private ShoesDao shoesDao;

    /**
     * 跳转到后台登录页
     *
     * @return
     */
    @RequestMapping("back")
    public String toBackIndex() {
        return "back/index";
    }

    /**
     * 跳转到index页
     *
     * @return
     */
    @RequestMapping(value = "l")
    public String toIndex() {
        return "web/index";
    }

    /**
     * 品牌故事
     *
     * @return
     */
    @RequestMapping(value = "story")
    public String toStory() {
        return "web/ppgs";
    }

    /**
     * 高级定制
     *
     * @return
     */
    @RequestMapping(value = "best")
    public String toBest() {
        return "web/gjdz";
    }

    /**
     * 护理保养
     *
     * @return
     */
    @RequestMapping(value = "care")
    public String toCare() {


        return "web/hlby";
    }

    /**
     * 精品鞋款
     *
     * @return
     */
    @RequestMapping(value = "shoes")
    public String toShoes() {


        return "web/jpxk";
    }

    /**
     * 法律声明
     *
     * @return
     */
    @RequestMapping(value = "law")
    public String toLaw() {
        return "web/flsm";
    }

    /**
     * 工作机会
     *
     * @return
     */
    @RequestMapping(value = "chance")
    public String toChance() {
        return "web/gzjh";
    }

    /**
     * 联系我们
     *
     * @return
     */
    @RequestMapping(value = "contact")
    public String toContact() {
        return "web/lxwm";
    }

    /**
     * 精品鞋款
     *
     * @return
     */
    @RequestMapping(value = "shoes/{id}")
    public String toShoes(@PathVariable String id, HttpServletRequest request) {
        Shoes shoes = shoesDao.selectShoesById(id);
        request.setAttribute("s", shoes);
        //查询同一款式的颜色
        List<String> strings = shoesDao.selectAllColor(shoes.getStyle(),shoes.getBelongSex());
        request.setAttribute("colors", strings);
        //查询同一款式的鞋底
        List<String> showBelows = shoesDao.selectAllShowsBelows(shoes.getName());
        request.setAttribute("shoeBelows", showBelows);
        //查找颜色相同的鞋子
        List<Shoes> shoes1 = shoesDao.selectAllByShoesLm(ShoesUtil.initSimilar(shoes),id);
        request.setAttribute("ss", shoes1);
        return "web/jpxk_xq";
    }

}
